#if !defined(AFX_ORDERPANELGRID_H__AFC86426_16CD_4B0A_BC44_DBE80EBFD127__INCLUDED_)
#define AFX_ORDERPANELGRID_H__AFC86426_16CD_4B0A_BC44_DBE80EBFD127__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// OrderPanelGrid.h : header file
//
#include "ugctrl.h"
#include "CurPriceInfo.h"
#include "KRSTHeader.h"
#include "DefineCol.h"
/////////////////////////////////////////////////////////////////////////////
// COrderPanelGrid window

class CMainOrderPanel;

typedef struct _CellPos
{
	int col;
	long row;
	long val;
	double quote;
} CellPos;

class COrderPanelGrid : public CUGCtrl
{
// Construction
public:
	COrderPanelGrid();

// Attributes
public:
	CMainOrderPanel* MainWnd() const { return m_pMainWnd; }
	void MainWnd(CMainOrderPanel* val) { m_pMainWnd = val; }
	int MouseMoveCol() const { return m_MouseMoveCol; }
	void MouseMoveCol(int val) { m_MouseMoveCol = val; }
	long MouseMoveRow() const { return m_MouseMoveRow; }
	void MouseMoveRow(long val) { m_MouseMoveRow = val; }

private:

	int m_CntColWidth;
	int m_QtyColWidth;
	int m_TimerID;
	unsigned int m_StartTime;
	unsigned int m_EndTime;
	void SetContentRow();
	int m_CenterCol;
	int m_BuyStopCol;
	int m_BuyOrderCol;
	int m_BuyQtyCol;
	int m_BuyCntCol;
	int m_SellOrderCol;
	int m_SellQtyCol;
	int m_SellCntCol;
	int m_SellStopCol;

	int oldCol;
	int oldRow;
	int oldCol2;
	int oldRow2;

	int oldHighRow;
	int oldLowRow;

	void RepaintCenterCol();

	double m_TopVal;

	int m_PrevCurRow;

	int m_RowHeight;
	int centerCol;

	int m_MaxRows;

	CellPos m_OldSellQtyPos[5];
	CellPos m_OldBuyQtyPos[5];

	CellPos m_OldSellCntPos[5];
	CellPos m_OldBuyCntPos[5];

	CUGCell* m_OldQTYCells[5];

	CellPos m_OldCurPos;

	long m_X;
	long m_Y;

	int m_MaxCol;
	int m_MouseMoveCol;
	long m_MouseMoveRow;
	int m_MouseLClickCol;
	long m_MouseLClickRow;
	int m_MouseRClickCol;
	int m_MouseRClickRow;

	int m_DragStartCol;
	int m_DragStartRow;
	int m_DragStopCol;
	int m_DragStopRow;
	CString m_DragStartVal;
	CString m_DragStopVal;
	BOOL m_bStartDrag;

	CMainOrderPanel* m_pMainWnd;

	POINT m_Prev;
	CString m_PrevPrice;
	CString m_PrevAmount;
	OrderVector* m_PrevOrderVector;
	double m_OldPrice;

	int oldClickRow;
	int oldClickCol;

	void DrawHighRowText();
	void QuickRedrawCell(int col, long row);
	bool FindQuote(CellPos a_CellPos [], double a_Quote);

// Operations
public:
	void ResetMousePoints();
	void RedrawMovingRect();
	void ResetOldCells();
	void RedrawQtyCntRows(int a_Upper, int a_Lower);
	void RedrawQtyCntRows();
	void RedrawOrderCells();
	int m_ColWidth;
	int m_CenterColWidth;

	void ClearQuotePos();
	void ClearOldQuotes();
	// Stop >> Cnt >> Qty >> Center;
	// Column define
	bool m_ShowStop;
	bool m_ShowCnt;
	bool m_ShowQty;

	unsigned int m_LayoutIndex;
	int SetColDefine();
	int GetTotalWidth();
	void SetColumnHeader();
	void ResetColWidth(int a_ColWidth);
	void ResetAllCells();
	void SetCellProp();
	int MaxCol() const { return m_MaxCol; }
	void MaxCol(int val) { m_MaxCol = val; }

	void SetOrderRowHeight(int a_RowHeight, int a_ColWidth);
	void ResizeWidths(int a_CenterWidth, int a_ColWidth);
	void ClearOrderInfo();
	int MaxRows() const { return m_MaxRows; }
	void MaxRows(int val) { m_MaxRows = val; }

	int ColWidth() const { return m_ColWidth; }
	void ColWidth(int val) { m_ColWidth = val; }

	int RowHeight() const { return m_RowHeight; }
	void RowHeight(int val) { m_RowHeight = val; }

	void SetPreCurRow(int a_Row)
	{
		m_PrevCurRow = a_Row;
	}

	double TopVal() const { return m_TopVal; }
	void TopVal(double val) { m_TopVal = val; }

	void DrawSelectedRect(int col, long row);
	void DrawSelectedRect(CDC* dc, int col, long row);
	void DrawSingleSelRect(int col, long row);
	void DrawMovingRect(int col, long row);
	void DrawClickRect(int col, long row);
	void ClearClickRect();
	void ClearMovingRect();
	void ShowCurVal(double a_CurVal, long a_Row, bool a_RealTime);
	int  FindRowOfCurVal(double a_CurVal);
	//void ShowCenterValues(double a_TopVal);
	void ShowCenterValues(double a_PreClose);
	void SetCenterTextColors(double a_PreClose);
	void SetTopVisibleRow(int a_CurValRow, int a_MaxVisibleRows);

	//void SetQuoteInfo(CCurPriceInfo& a_PriceInfo);
	void SetQuoteInfo(CSymbolInfo& a_SymbolInfo);
	void InitQuoteInfo(CSymbolInfo& a_SymbolInfo);

	int FindRow(double a_Val);

	void ShowOrders(mapOrder& a_OrderMap);
	void ShowOrders(CAccountInfo* a_AccInfo);
	void ShowOrdersByBuySell(CAccountInfo* a_AccInfo);
	void ShowOrders();
	void ShowNewOrder(CAccountInfo* a_AccInfo, COrderInfo* a_Order, COrderInfo* a_PrevOrder);
	void ShowNewOrder(CPositionInfo* a_Posi, COrderInfo* a_Order);
	void ShowConfirmOrder(CAccountInfo* a_AccInfo, COrderInfo* a_Order);
	void ShowUnfilledOrders(CPositionInfo* a_Posi);

	void ClearCol(int a_Col);

	double SetTopVal(double a_Input);

	void ClearColText(int a_Col);

	int CalcTotalWidth();

	int CalcFixedTotalWidth(int& a_ExCnt);

	CFont* m_CurValFont;
	CFont* m_DefaultFont;

	BOOL m_bDrawing;

	void ShowHighLow(CSymbolInfo* a_Sym);
	
// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(COrderPanelGrid)
	//***** Over-ridable Notify Functions *****
	virtual void OnSetup();

	//}}AFX_VIRTUAL
private:
	void DrawOrderLine(int a_Col, long a_Row);
	void DrawCancelLine(int a_Col, long a_Row);
	//void ShowCenterValues();
// Implementation
public:
	virtual ~COrderPanelGrid();

	virtual void OnKeyDown(UINT *vcKey,BOOL processed);
	virtual void OnCharDown(UINT *vcKey,BOOL processed);

	virtual void OnMouseMove(int col,long row,POINT *point,UINT nFlags,BOOL processed=0);
	virtual void OnLClicked(int col,long row,int updn,RECT *rect,POINT *point,int processed);
	virtual void OnRClicked(int col,long row,int updn,RECT *rect,POINT *point,int processed);
	virtual void OnDClicked(int col,long row,RECT *rect,POINT *point,BOOL processed);

	virtual DROPEFFECT OnDragEnter(COleDataObject* pDataObject);
	virtual DROPEFFECT OnDragOver(COleDataObject* pDataObject, int col, long row);
	virtual DROPEFFECT OnDragDrop(COleDataObject* pDataObject, int col, long row);


	void MakeOrder(lpExpTr0988O_sub a_Order, CString a_PrePrice, CString a_NewPrice, COrderInfo* a_PreOrder);



	// Generated message map functions
protected:
	//{{AFX_MSG(COrderPanelGrid)
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_ORDERPANELGRID_H__AFC86426_16CD_4B0A_BC44_DBE80EBFD127__INCLUDED_)
